import _ from 'lodash';
import moment from 'moment';

const changeTradeTypeFn = (obj: any, tableData: any[]) => {
  const arr = Object.keys(obj);
  const key = arr[0];
  const id = key.split('@')[1];
  let resetKey = '';
  if (key.indexOf('tradeType') > -1) {
    const index = _.findIndex(tableData, (n: any) => n.id == id);
    tableData[index].tradeType = obj[key];
    resetKey = obj[key] === 1 ? `buyLowPrice@${id}` : `sellUpPrice@${id}`;
  }
  return { tableData, resetKey };
};

const disabledDate = (current: any) => {
  return current && current < moment().add(1, 'days').endOf('day');
};

export { changeTradeTypeFn, disabledDate };
